Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

134
Vistas
what is the equivalent method for .pack("H*")].pack("m0") of Ruby in Javascript?

In Ruby, I use function .pack("H*")].pack("m0") to encode a hex message string to base64 string.

ex.

msg_hex = 8308862831031591345F010101020663602A06E300000000EF934E0C5B29E50E000000000000000000000310000000004F04010000010000
msg_hex.pack("H*")].pack("m0") => gwiGKDEDFZE0XwEBAQIGY2AqBuMAAAAA75NODFsp5Q4AAAAAAAAAAAAAAxAAAAAATwQBAAABAAA=

In Javascript, I am looking for an equivalent method to convert message to 64base message. Some answers tell useing Buffer.from(msg_hex).toString('base64'), but the result is different.

const msg_hex = 8308862831031591345F010101020663602A06E300000000EF934E0C5B29E50E000000000000000000000310000000004F04010000010000
Buffer.from(msg_hex).toString('base64') // => ODMwODg2MjgzMTAzMTU5MTM0NUYwMTAxMDEwMjA2NjM2MDJBMDZFMzAwMDAwMDAwRUY5MzRFMEM1QjI5RTUwRTAwMDAwMDAwMDAwMDAwMDAwMzEwMDAwMDAwMDA0RjA0MDAwMDAwMDEwMDAw

what is the equivalent method for .pack("H*")].pack("m0") of Ruby in Javascript?

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

You was nearly there with what you supplied.

You just forgot to tell Buffer.from what you was supplying, as default if you send a string it's just going to store it as a string. But what you wanted was to decode the source as hex and then store as binary.

So doing ->

Buffer.from(msg_hex, 'hex').toString('base64') 

IOW: you just missed the second parameter hex..

about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda